package com.dayatang.hrm.compensation.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;

public class DateVersionUtils {

	public static Date getPreviousVersionTimestamp(Date date) {
		return new Date(date.getTime() - 1000);
	}

	public static Date getCurrentlyVersionTimestamp(Date date) {
		return date;
	}

	public static Date getBeginOfDay(Date day) throws Exception {
		String old = DateFormatUtils.format(day, "yyyy-MM-dd");

		String newDate = old + " 00:00:00";

		return DateUtils.parseDate(newDate,
				new String[] { "yyyy-MM-dd HH:mm:ss" });
	}

	public static Date getEndOfDay(Date day) throws Exception {
		String old = DateFormatUtils.format(day, "yyyy-MM-dd");

		String newDate = old + " 23:59:59";

		return DateUtils.parseDate(newDate,
				new String[] { "yyyy-MM-dd HH:mm:ss" });
	}
	
	public static Date getNextDay(Date day) {
		Calendar now = GregorianCalendar.getInstance();
		now.setTime(day);
		// 加一天
		now.add(Calendar.DAY_OF_YEAR, 1);
		
		return now.getTime();
	}

	public static void main(String[] args) throws Exception {
		System.out.println(getNextDay(new Date()));
	}
}
